<template>
	<div class="icons">
		<swiper :options="swiperOption">
			 <swiper-slide v-for="(page, index) of pages" :key="index">
					<div class="icon" v-for="item of page" :key="item.id">
						<img class="icon-img" :src="item.imgUrl" />
						<p>{{item.desc}}</p>
					</div>
				</swiper-slide>
				<div class="swiper-pagination"  slot="pagination"></div>
		</swiper>
	</div>
</template>

<script>
	export default {
		name: 'HomeIcons',
		props: {
			list: Array
		},
		data: function(){
			return {
				swiperOption : {
					pagination : '.swiper-pagination',
					autoplay : false
				}
			}
		},
		computed: {
			pages: function (){
				const pages = [];
				this.list.forEach(function(item,index){
					const page = Math.floor(index/8);
					if(!pages[page]){
						pages[page] = [];
					}
					pages[page].push(item);
				})
				return pages;
			}
		}
	}
</script>

<style lang="stylus" scoped>
@import '~styles/mixins.styl'

	.icons >>> .swiper-container
		overflow: hidden
		height: 0
		padding-bottom: 55%
	.icons
		position: relative
	.swiper-pagination
		position: absolute
		bottom: 0
	.icon
		float: left
		overflow: hidden
		width: 25%
		height: 0
		padding: .3rem
		padding-top: .2rem
		padding-bottom: 25%
		box-sizing: border-box
		img
			width: 100%
			min-height: 1.275rem
		p
			text-align: center
			font-size: .272rem
			margin-top: .2rem
			ellipsis()			
</style>